package jdbc;
/**
 * 执行DML语句-INSERT
 */
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

/*
执行DML语句-INSERT
 */
public class JDBCDemo2 {
    public static void main(String[] args) throws Exception {
        //向userinfo表中插入一条记录
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection conn= DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root",
                "root");
        Statement state = conn.createStatement();
        String sql="INSERT INTO userinfo(username,password,nickname,age)\n" +
                "        VALUES(\"阿绿\",123,\"小绿\",18);";

        /*
            int executeUpdate(String sql)
            执行DML语句(INSERT、UPDATE、DELETE)，
            返回值为执行后影响了表中多少条记录
         */
        int a = state.executeUpdate(sql);
        System.out.println("插入了"+a+"多少条数据");
        conn.close();
    }
}
